﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Services.System.ClassRoom;
using static Simple.Services.ClassDynamicCreateOrUpdateModel;

namespace Simple.WebApi.Controllers.System;

/// <summary>
/// 班级动态
/// </summary>
[Route("api/ClassDynamic/[action]")]
[ApiController]
[Authorize]
public class ClassDynamicController : ControllerBase
{
    private readonly ClassDynamicService _classDynamicService;

    public ClassDynamicController(ClassDynamicService classDynamicService)
    {
        _classDynamicService = classDynamicService;
    }

    /// <summary>
    /// 查询班级动态内容详情
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> GetClassDynamicInfo([FromQuery] Guid? Id)
    {
        var data = await _classDynamicService.GetAsync(Id);
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 班级动态列表分页查询(PC端管理后台查询)
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> Page([FromQuery] ClassDynamicQueryPageInputModel model)
    {
        var data = await _classDynamicService.GetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 班级动态列表分页查询（移动端）
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> MovePage([FromQuery] ClassDynamicQueryPageInputModel model)
    {
        var data = await _classDynamicService.MoveGetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 班级动态列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> List()
    {
        var data = await _classDynamicService.GetAll();
        return AppResult.Status200OK(data: data);
    }

    /// <summary>
    /// 发布班级动态
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Add([FromForm] ClassDynamicCreateOrUpdateModel model)
    {
        await _classDynamicService.AddAsync(model);
        return AppResult.Status200OK("新增成功");
    }

    /// <summary>
    /// 编辑班级动态
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Edit([FromForm] ClassDynamicCreateOrUpdateModel model)
    {
        await _classDynamicService.UpdateAsync(model);
        return AppResult.Status200OK("更新成功");
    }

    /// <summary>
    /// 发布班级动态(移动端)
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> MoveAdd([FromBody] MoveClassDynamicCreateOrUpdateModel model)
    {
        await _classDynamicService.MoveAddAsync(model);
        return AppResult.Status200OK("新增成功");
    }

    /// <summary>
    /// 编辑班级动态（移动端）
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> MoveAddEdit([FromBody] MoveClassDynamicCreateOrUpdateModel model)
    {
        await _classDynamicService.MoveUpdateAsync(model);
        return AppResult.Status200OK("更新成功");
    }

    /// <summary>
    /// 删除班级动态
    /// </summary>
    /// <param name="IdList"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> Delete([FromBody] List<Guid?> IdList)
    {
        await _classDynamicService.DeleteAsync(IdList);
        return AppResult.Status200OK("删除成功");
    }

    /// <summary>
    /// 获取当前登陆人授权的班级列表
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> GetMyAuthClassList()
    {
        var data = await _classDynamicService.GetClassAuthorizationInfo();
        return AppResult.Status200OK(data: data?.Select(c => new ClassDynamicSysClassesDto { ClassId = c.Id.ToString() ?? String.Empty, ClassName = c.Name }));
    }

    /// <summary>
    /// 屏蔽或恢复
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> ChangeStatus([FromQuery] ChangeStatusModel model)
    {
        var data = await _classDynamicService.ChangeStatus(model);
        return AppResult.Status200OK(model.Status == 2 ? "屏蔽成功！" : "恢复成功！");
    }

    /// <summary>
    /// 留言
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<AppResult> LeaveMessages([FromBody] ClassDynamicLeaveMessagesDto input)
    {
        var data = await _classDynamicService.LeaveMessages(input);
        return AppResult.Status200OK("留言成功!");
    }

    /// <summary>
    /// 我的动态列表分页查询（移动端）
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<AppResult> MoveMyClassDynamicGetPage([FromQuery] ClassDynamicQueryPageInputModel model)
    {
        var data = await _classDynamicService.MoveMyClassDynamicGetPageAsync(model);
        return AppResult.Status200OK(data: data);
    }
}
